﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
//using System.Random;



namespace AFCEPF.BankApplication.DAL
{
    /// <summary>
    /// Utility class for handling random
    /// information.
    /// </summary>
    public class Random : System.Random
    {
        

        /// <summary>
        /// Constructor
        /// </summary>
        public Random() :this (DateTime.Now.Millisecond)
        {}

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="seed">Seed value</param>
        public Random(int seed) : base(seed)
        {}



        /// <summary>
        /// returns a random date/time for a specific date range.
        /// </summary>
        /// <param name="start">Start time</param>
        /// <param name="end">End time</param>
        /// <returns>A random date/time between the start and end times</returns>
        public virtual DateTime NextDate(DateTime start, DateTime end)
        {
            if (start > end)
                throw new ArgumentException("The start value must be earlier than the end value");
            return start + new TimeSpan((long)(new TimeSpan(end.Ticks - start.Ticks).Ticks * NextDouble()));
        }

        /// <summary>
        /// returns a randomly generated string
        /// </summary>
        /// <param name="length">length of the string</param>
        /// <returns>a randomly generated string of the specified length</returns>
        public virtual string NextString(int length)
        {
            if (length < 1)
                return "";
            return NextString(length, ".");
        }

        /// <summary>
        /// Returns a randomly generated string of a specified length, containing
        /// only a set of characters
        /// </summary>
        /// <param name="length">length of the string</param>
        /// <param name="allowedCharacters">Characters that are allowed in the string</param>
        /// <returns>A randomly generated string of the specified length, containing only the allowed characters.</returns>
        public virtual string NextString(int length, string allowedCharacters)
        {
            if (length < 1)
                return "";
            return NextString(length, allowedCharacters, length);
        }

        /// <summary>
        /// Returns a randomly generated string of a specified length, containing
        /// only a set of characters, and at max a specified number of non alpha numeric characters.
        /// </summary>
        /// <param name="length">length of the string</param>
        /// <param name="allowedCharacters">Characters allowed in the string</param>
        /// <param name="numberOfNonAlphaNumericsAllowed">Number of non alpha numeric characters allowed.</param>
        /// <returns>A randomly generated string of a specified length, containing only a set of characters, and at max a specified number of non alpha numeric characters.</returns>
        public virtual string NextString(int length, string allowedCharacters, int numberOfNonAlphaNumericsAllowed)
        {
            if (length < 1)
                return "";
            StringBuilder TempBuilder = new StringBuilder();
            Regex Comparer = new Regex(allowedCharacters);
            Regex alphaNumbericComparer = new Regex("[0-9a-zA-z]");
            int Counter = 0;
            while (TempBuilder.Length < length)
            {
                string tempValue = new string(Convert.ToChar(Convert.ToInt32(System.Math.Floor(94 * NextDouble() + 32))), 1);
                if (Comparer.IsMatch(tempValue))
                {
                    if (!alphaNumbericComparer.IsMatch(tempValue) && numberOfNonAlphaNumericsAllowed > Counter)
                    {
                        TempBuilder.Append(tempValue);
                        ++Counter;
                    }
                    else if (alphaNumbericComparer.IsMatch(tempValue))
                    {
                        TempBuilder.Append(tempValue);
                    }
                }
            }
            return TempBuilder.ToString();
        }
        
        /// <summary>
        /// Returns a random boolean value
        /// </summary>
        /// <returns>returns a boolean</returns>
        public virtual bool NextBool()
        {
            if (Next(0, 2) == 1)
                return true;
            return false;
        }

        /// <summary>
        /// Gets a random enum value
        /// </summary>
        /// <typeparam name="T">The enum type</typeparam>
        /// <returns>A random value from an enum</returns>
        public virtual T NextEnum<T>()
        {
            Array Values = Enum.GetValues(typeof(T));
            int Index = Next(0, Values.Length);
            return (T)Values.GetValue(Index);
        }

        /// <summary>
        /// Randomly generates a new time span
        /// </summary>
        /// <param name="Start">Start time span</param>
        /// <param name="End">End time span</param>
        /// <returns>A time span between the start and end</returns>
        public virtual TimeSpan NextTimeSpan(TimeSpan Start, TimeSpan End)
        {
            if (Start > End)
                throw new ArgumentException("The start value must be earlier than the end value");
            return Start + new TimeSpan((long)(new TimeSpan(End.Ticks - Start.Ticks).Ticks * NextDouble()));
        }


        public IList<string> names = new List<string>() {"JAMES","JOHN","ROBERT","WILLIA","DAVID","RICHARD",
                                                        "CHARLES","JOSEPH","THOMAS","CHRISTOPHER","DANIEL",
                                                        "PAUL","MARK","DONALD","GEORGE","KENNETH","STEVEN",
                                                        "EDWARD","BRIAN","RONALD","ANTHONY","KEVIN",
                                                        "JASON","MATTHEW","GARY","TIMOTHY","JOSE","LARRY",
                                                        "JEFFREY","FRANK","SCOTT","ERIC","STEPHEN",
                                                        "ANDREW","RAYMOND","GREGORY","JOSHUA","JERRY",
                                                        "DENNIS","WALTER","PATRICK","PETER","HAROLD",
                                                        "DOUGLAS","HENRY","CARL","ARTHUR","RYAN",
                                                        "ROGER","JOE","JUAN","JACK","ALBERT",
                                                        "JONATHAN","JUSTIN","TERRY","GERALD","KEITH",
                                                        "SAMUEL","WILLIE","RALPH","LAWRENCE","NICHOLAS",
                                                        "ROY","BENJAMIN","BRUCE","BRANDON","ADAM",
                                                        "HARRY","FRED","WAYNE","BILLY","STEVE",
                                                        "LOUIS","JEREMY","AARON","RANDY","HOWARD",
                                                        "EUGENE","CARLOS","RUSSELL","BOBBY","VICTOR",
                                                        "MARTIN","ERNEST","PHILLIP","TODD","JESSE",
                                                        "CRAIG","ALAN","SHAWN","CLARENCE","SEAN",
                                                        "PHILIP","CHRIS","JOHNNY","EARL","JIMMY",
                                                        "ANTONIO","DANNY","BRYAN","TONY","LUIS",
                                                        "MIKE","STANLEY","LEONARD","NATHAN","DALE",
                                                        "MANUEL","RODNEY","CURTIS","NORMAN","ALLEN",
                                                        "MARVIN","VINCENT","GLENN","JEFFERY","TRAVIS",
                                                        "JEFF","CHAD","JACOB","LEE","MELVIN",
                                                        "ALFRED","KYLE","FRANCIS","BRADLEY","JESUS",
                                                        "HERBERT","FREDERICK","RAY","JOEL","EDWIN",
                                                        "DON","EDDIE","RICKY","TROY","RANDALL",
                                                        "BARRY","ALEXANDER","BERNARD","MARIO","LEROY",
                                                        "FRANCISCO","MARCUS","MICHEAL","THEODORE","CLIFFORD",
                                                        "MIGUEL","OSCAR","JAY","JIM","TOM",
                                                        "CALVIN","ALEX","JON","RONNIE","BILL",
                                                        "LLOYD","TOMMY","LEON","DEREK","WARREN",
                                                        "DARRELL","JEROME","FLOYD","LEO","ALVIN",
                                                        "TIM","WESLEY","GORDON","DEAN","GREG",
                                                        "JORGE","DUSTIN","PEDRO","DERRICK","DAN",
                                                        "LEWIS","ZACHARY","COREY","HERMAN","MAURICE",
                                                        "VERNON","ROBERTO","CLYDE","GLEN","HECTOR",
                                                        "SHANE","RICARDO","SAM","RICK","LESTER",
                                                        "BRENT","RAMON","CHARLIE","TYLER","GILBERT",
                                                        "GENE","MARC","REGINALD","RUBEN","BRETT",
                                                        "ANGEL","NATHANIEL","RAFAEL","LESLIE","EDGAR",
                                                        "MILTON","RAUL","BEN","CHESTER","CECIL",
                                                        "DUANE","FRANKLIN","ANDRE","ELMER","BRAD",
                                                        "GABRIEL","RON","MITCHELL","ROLAND","ARNOLD",
                                                        "HARVEY","JARED","ADRIAN","KARL","CORY",
                                                        "CLAUDE","ERIK","DARRYL","JAMIE","NEIL",
                                                        "JESSIE","CHRISTIAN","JAVIER","FERNANDO","CLINTON",
                                                        "TED","MATHEW","TYRONE","DARREN","LONNIE",
                                                        "LANCE","CODY","JULIO","KELLY","KURT",
                                                        "ALLAN","NELSON","GUY","CLAYTON","HUGH",
                                                        "MAX","DWAYNE"};
    
    }
}